package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * 攻略文章管理
 */
@Setter
@Getter
public class StrategyDetail {
    public static final int STATE_NORMAL = 0;//草稿状态
    public static final int STATE_RELEASE = 1;//发布状态

    private Long id; //id

    private String title; //标题

    private Date createTime;//创建时间

    private Date releaseTime;//发布时间

    private Integer sequence;//序号

    private StrategyCatalog catalog;//所属目录类型

    private String coverUrl; //文章的封面

    private Integer state; //文章状态

    private StrategyContent strategyContent;//文章内容



    public String getStateDisplay(){
        if (state==null){
            return "";
        }else if (state == STATE_NORMAL){
            return "未发布";
        }else if (state==STATE_RELEASE){
            return "发布";
        }else {
            return "";
        }
    }

    //编辑框的回显
    public String getJsonString(){
        Map<String,Object> map = new HashMap<>();
        map.put("id",id);
        map.put("title",title);
        map.put("releaseTime", DateUtil.date2string(releaseTime, "yyyy-MM-dd"));
        map.put("coverUrl",coverUrl);
        if (catalog!=null) {
            map.put("catalogId",catalog.getId());
            map.put("strategyId", catalog.getStrategyId());
        }
        map.put("sequence",sequence);
        map.put("state",state);
        return JSONUtil.toJSONString(map);
    }

}